import request from '@/utils/request'

/**
 * 预警接收人管理相关API
 */
export default {
  /**
   * 获取接收人列表
   * @param {number} params.pageNum - 页码
   * @param {number} params.pageSize - 每页条数
   * @param {string} params.recipientName - 姓名搜索关键词
   * @param {string} params.recipientEmail - 邮箱搜索关键词
   * @returns {Promise}
   */
  getRecipientList(params) {
    return request({
      url: '/recipient/list',
      method: 'get',
      params
    })
  },
  // 上传头像
  uploadAvatar(file) {
    const formData = new FormData()
    formData.append('file', file)
    return request({
      url: '/recipient/upload',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },


  /**
   * 添加预警接收人
   * @param {Object} data - 接收人信息
   * @param {string} data.recipientName - 姓名
   * @param {string} data.recipientEmail - 邮箱
   * @param {string} data.recipientPhone - 电话
   * @param {string} data.recipientProductCategory - 产品分类
   * @param {string} data.recipientRemarks - 备注
   * @returns {Promise}
   */
  addRecipient(data) {
    return request({
      url: '/recipient',
      method: 'post',
      data
    })
  },

  /**
   * 更新预警接收人
   * @param {Object} data - 接收人信息
   * @param {number} data.recipientId - 接收人ID
   * @param {string} data.recipientName - 姓名
   * @param {string} data.recipientEmail - 邮箱
   * @param {string} data.recipientPhone - 电话
   * @param {string} data.recipientProductCategory - 产品分类
   * @param {string} data.recipientRemarks - 备注
   * @returns {Promise}
   */
  updateRecipient(data) {
    return request({
      url: `/recipient/${data.recipientId}`,
      method: 'put',
      data
    })
  },

  /**
   * 删除预警接收人
   * @param {number} recipientId - 接收人ID
   * @returns {Promise}
   */
  deleteRecipient(recipientId) {
    return request({
      url: `/recipient/${recipientId}`,
      method: 'delete'
    })
  },

  /**
   * 导出接收人列表
   * @returns {Promise}
   */
  exportRecipient() {
    return request({
      url: '/recipient/export',
      method: 'get',
      responseType: 'blob' // 二进制流响应
    })
  },

  /**
   * 导入接收人列表
   * @param {File} file - Excel文件
   * @returns {Promise}
   */
  importRecipient(file) {
    const formData = new FormData()
    formData.append('file', file)
    return request({
      url: '/recipient/import',
      method: 'post',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  /**
   * 下载Excel模板
   * @returns {Promise}
   */
  downloadTemplate() {
    return request({
      url: '/recipient/import/template',
      method: 'get',
      responseType: 'blob' // 二进制流响应
    })
  }
}
